package com.wh.controller.instorehouse;


import com.wh.controller.initial.StorehouseController;
import com.wh.pojo.Product;
import com.wh.pojo.Purchase;
import com.wh.pojo.Storehouse;
import com.wh.pojo.Supplier;
import com.wh.service.instorehouse.PurchaseService;
import com.wh.vo.PageResult;
import com.wh.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/purchase/")
public class PurchaseController {

    @Autowired
    private PurchaseService purchaseService;

    @GetMapping("list")
    public SysResult getPurchaseList(PageResult pageResult){
        pageResult = purchaseService.getPurchaseList(pageResult);
        return SysResult.success(pageResult);
    }

    @PostMapping("addPurchase")
    public SysResult addPurchase(@RequestBody Purchase purchase){
        purchaseService.addPurchase(purchase);
        return SysResult.success();
    }

    @GetMapping("getProductList")
    public SysResult getProductList(Product product){
//        String name = (String) map.get("name");
//        System.out.println(product.getName());
//        System.out.println(map.toString());
        List<Product> productList = purchaseService.getProductList(product.getName());
        return SysResult.success(productList);
    }

    @GetMapping("getSupplier")
    public SysResult getSupplier(){
        List<Supplier> supplierList = purchaseService.getSupplier();
        return SysResult.success(supplierList);
    }

    @GetMapping("getStorehouse")
    public SysResult getStorehouse(){
        List<Storehouse> storehouseList = purchaseService.getStorehouse();
        return SysResult.success(storehouseList);
    }

    @DeleteMapping("delete/{purchaseId}")
    public SysResult deletePurchase(@PathVariable String purchaseId){
        purchaseService.deletePurchase(purchaseId);
        return SysResult.success();
    }

    @PutMapping("updata")
    public SysResult updataPurchase(@RequestBody Purchase purchase){
        purchaseService.updataPurchase(purchase);
        return SysResult.success();
    }
}
